package cn.jsj.finance.bank;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jsj.object.FrontInvoiceInfo;
import cn.jsj.pojo.TblInvoiceManage;
import cn.jsj.utils.SysLogger;

/**
 * 加载所有发票信息
 * @author LI
 *
 */
 public class InvoiceInfoRequest extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
	 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 	// 调试信息
		 	cn.jsj.utils.SysLogger.PrintInfo("加载所有的发票信息");

		 	//获得参数：1.第几条开始。2.一页显示几条
			int startNumb=Integer.parseInt(request.getParameter("start"));
			int totalNumb=Integer.parseInt(request.getParameter("limit"));

			//调试信息
			cn.jsj.utils.SysLogger.PrintInfo("start---->"+startNumb+"   total--------->"+totalNumb);

			//获得发票信息条数
			cn.jsj.dao.TblInvoiceManageDAO timd=new cn.jsj.dao.TblInvoiceManageDAO();
			int invoiceNumber=timd.getAllInvoiceInfoNumb();
			//发票信息列表
			java.util.List<TblInvoiceManage> invoiceList=new java.util.LinkedList<TblInvoiceManage>();
			invoiceList=timd.getAllInvoiceInfo(startNumb, totalNumb);



			//前台发票信息对象队列
			java.util.List<FrontInvoiceInfo> frontInvoiceInfo=new java.util.LinkedList<FrontInvoiceInfo>();

			// 转换为前台发票信息对象
			cn.jsj.object.rebuild.InvoiceInfoRebuild iir=new cn.jsj.object.rebuild.InvoiceInfoRebuild();
			for(int i=0;i<invoiceList.size();i++){
				cn.jsj.object.FrontInvoiceInfo fii=iir.rebuildInvoiceInfo(invoiceList.get(i));
				frontInvoiceInfo.add(fii);
			}

			//转换成JSON型数据
			cn.jsj.utils.ProduceJsonData pjd=new cn.jsj.utils.ProduceJsonData();
			String jsonData=pjd.jsonFromList(frontInvoiceInfo, invoiceNumber);

			//调试信息
			SysLogger.PrintInfo(jsonData);
			//输出到客户端
			java.io.PrintWriter pw=response.getWriter();
			pw.println(jsonData);
			pw.flush();
			pw.close();
	}
}